<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015-08-25
 * Time: 16:15
 */
class b2c_ctl_wap_myorders extends b2c_ctl_wap_common{
    function __construct(&$app){
        parent::__construct($app);
        $shopname = app::get('wap')->getConf('wap.name');
        $this->shopname =$shopname;
        if(isset($shopname)){
            $this->title = app::get('b2c')->_('樱淘社').$shopname;
            $this->keywords = app::get('b2c')->_('樱淘社').$shopname;
            $this->description = app::get('b2c')->_('樱淘社').$shopname;
        }
        $this->action = $this->_request->get_act_name();
        if(!$this->action) $this->action = 'index';
        $this->pagedata['res_url'] = $this->app->res_url;
        $this->userObject = kernel::single('b2c_user_object');
        /** end **/
    }

    function allorders(){
//        全部订单
        $input['method'] = array("file"=>"mobileapi_rpc_member","action"=>"orders");
        $res = $this->getApi($input);
        $this->pagedata['allorders'] = $res['data'];
//        待付款
        $input['method'] = array("file"=>"mobileapi_rpc_member","action"=>"orders");
        $input['data'] = array('pay_status'=>0);
        $res2 = $this->getApi($input);
        $this->pagedata['payorders'] = $res2['data'];
//        待发货
        $input['method'] = array("file"=>"mobileapi_rpc_member","action"=>"orders");
        $input['data'] = array('ship_status'=>'0');
        $res3 = $this->getApi($input);
        $this->pagedata['sendorders'] = $res3['data'];
//        待收货
        $input['method'] = array("file"=>"mobileapi_rpc_member","action"=>"orders");
        $input['data'] = array('ship_status'=>1);
        $res4 = $this->getApi($input);
        $this->pagedata['colorders'] = $res4['data'];
//        待推荐
        $input['method'] = array("file"=>"mobileapi_rpc_member","action"=>"get_order_opinions");
        $res5 = $this->getApi($input);
        $this->pagedata['recorders'] = $res5['data'];

        $this->pagedata['url'] = kernel::base_url(1).$this->gen_url(array('app'=>'b2c','ctl'=>'wap_myorders','act'=>'canorder'));
        $this->pagedata['rurl'] = kernel::base_url(1).$this->gen_url(array('app'=>'b2c','ctl'=>'wap_myorders','act'=>'allorders'));

        $this->page('wap/myorders/allorders.html');
    }
//订单详情
    function ordermsg($oid){
        $input['method'] = array("file"=>"mobileapi_rpc_member","action"=>"orderdetail");
        $input['data'] = array('order_id'=>$oid);
        $res = $this->getApi($input);

        $pay_status = $res['data']['order']['pay_status'];
        $ship_status = $res['data']['order']['ship_status'];
        $status = $res['data']['order']['status'];
//待付款
        if($pay_status == '0' && $ship_status == '0' && $status == 'active'){
            $this->pagedata['order_id'] = $res['data']['order']['order_id'];
            $this->pagedata['time'] = date("Y-m-d H:i:s",$res['data']['order']['createtime']);
            $this->pagedata['mobile'] = $res['data']['order']['consignee']['mobile'];
            $this->pagedata['name'] = $res['data']['order']['consignee']['name'];
            $this->pagedata['addr'] = $res['data']['order']['consignee']['addr'];
            $this->pagedata['shipping_name'] = $res['data']['order']['shipping']['shipping_name'];
            $this->pagedata['goods'] = $res['data']['order']['goods_items'];//
            $this->pagedata['goods_cost'] = $res['data']['order']['cost_item'];
            $this->pagedata['shipping_cost'] = $res['data']['order']['shipping']['cost_shipping'];
            $this->pagedata['pmt_order'] = $res['data']['order']['pmt_order'];
            $this->pagedata['order_chgpointmoney'] = $res['data']['order']['order_chgpointmoney'];
            $this->pagedata['total_amount'] = $res['data']['order']['total_amount'];
            $this->pagedata['total_amount'] = $res['data']['order']['total_amount'];

            $input['method'] = array("file"=>"mobileapi_rpc_order","action"=>"select_payment");
            $input['data'] = array('hipping[shipping_id]'=>$res['data']['order']['shipping']['shipping_id']);
            $pay = $this->getApi($input);
            $this->pagedata['pay'] = $pay['data'];


            $this->pagedata['url'] = kernel::base_url(1).$this->gen_url(array('app'=>'b2c','ctl'=>'wap_myorders','act'=>'canorder'));
            $this->pagedata['rurl'] = kernel::base_url(1).$this->gen_url(array('app'=>'b2c','ctl'=>'wap_myorders','act'=>'allorders'));
//            支付链接
            $this->pagedata['purl'] = '';

            $this->page('wap/myorders/paymsg.html');
// 待发货
        }elseif($pay_status == '1' && $ship_status == '0' && $status == 'active'){
            $this->pagedata['order_id'] = $res['data']['order']['order_id'];
            $this->pagedata['time'] = date("Y-m-d H:i:s",$res['data']['order']['createtime']);
            $this->pagedata['mobile'] = $res['data']['order']['consignee']['mobile'];
            $this->pagedata['name'] = $res['data']['order']['consignee']['name'];
            $this->pagedata['addr'] = $res['data']['order']['consignee']['addr'];
            $this->pagedata['shipping_name'] = $res['data']['order']['shipping']['shipping_name'];
            $this->pagedata['goods'] = $res['data']['order']['goods_items'];//
            $this->pagedata['goods_cost'] = $res['data']['order']['cost_item'];
            $this->pagedata['shipping_cost'] = $res['data']['order']['shipping']['cost_shipping'];
            $this->pagedata['pmt_order'] = $res['data']['order']['pmt_order'];
            $this->pagedata['order_chgpointmoney'] = $res['data']['order']['order_chgpointmoney'];
            $this->pagedata['total_amount'] = $res['data']['order']['total_amount'];
            $this->pagedata['pay'] = $res['data']['order']['payment']['app_display_name'];

            $this->page('wap/myorders/sendmsg.html');
// 待收货
        }elseif($pay_status == '1' && $ship_status == '1' && $status == 'active'){
            $this->pagedata['order_id'] = $res['data']['order']['order_id'];
            $this->pagedata['time'] = date("Y-m-d H:i:s",$res['data']['order']['createtime']);
            $this->pagedata['mobile'] = $res['data']['order']['consignee']['mobile'];
            $this->pagedata['name'] = $res['data']['order']['consignee']['name'];
            $this->pagedata['addr'] = $res['data']['order']['consignee']['addr'];
            $this->pagedata['shipping_name'] = $res['data']['order']['shipping']['shipping_name'];
            $this->pagedata['goods'] = $res['data']['order']['goods_items'];//
            $this->pagedata['goods_cost'] = $res['data']['order']['cost_item'];
            $this->pagedata['shipping_cost'] = $res['data']['order']['shipping']['cost_shipping'];
            $this->pagedata['pmt_order'] = $res['data']['order']['pmt_order'];
            $this->pagedata['order_chgpointmoney'] = $res['data']['order']['order_chgpointmoney'];
            $this->pagedata['total_amount'] = $res['data']['order']['total_amount'];
            $this->pagedata['pay'] = $res['data']['order']['payment']['app_display_name'];

            $this->page('wap/myorders/colmsg.html');
// 待推荐
        }elseif($pay_status == '1' && $ship_status == '1' && $status == 'finish'){
            $this->pagedata['order_id'] = $res['data']['order']['order_id'];
            $this->pagedata['time'] = date("Y-m-d H:i:s",$res['data']['order']['createtime']);
            $this->pagedata['mobile'] = $res['data']['order']['consignee']['mobile'];
            $this->pagedata['name'] = $res['data']['order']['consignee']['name'];
            $this->pagedata['addr'] = $res['data']['order']['consignee']['addr'];
            $this->pagedata['shipping_name'] = $res['data']['order']['shipping']['shipping_name'];
            $this->pagedata['goods'] = $res['data']['order']['goods_items'];//
            $this->pagedata['goods_cost'] = $res['data']['order']['cost_item'];
            $this->pagedata['shipping_cost'] = $res['data']['order']['shipping']['cost_shipping'];
            $this->pagedata['pmt_order'] = $res['data']['order']['pmt_order'];
            $this->pagedata['order_chgpointmoney'] = $res['data']['order']['order_chgpointmoney'];
            $this->pagedata['total_amount'] = $res['data']['order']['total_amount'];
            $this->pagedata['pay'] = $res['data']['order']['payment']['app_display_name'];

            $this->page('wap/myorders/recmsg.html');
// 作废订单
        }elseif($status == 'dead'){
            $this->pagedata['order_id'] = $res['data']['order']['order_id'];
            $this->pagedata['time'] = date("Y-m-d H:i:s",$res['data']['order']['createtime']);
            $this->pagedata['mobile'] = $res['data']['order']['consignee']['mobile'];
            $this->pagedata['name'] = $res['data']['order']['consignee']['name'];
            $this->pagedata['addr'] = $res['data']['order']['consignee']['addr'];
            $this->pagedata['shipping_name'] = $res['data']['order']['shipping']['shipping_name'];
            $this->pagedata['goods'] = $res['data']['order']['goods_items'];//
            $this->pagedata['goods_cost'] = $res['data']['order']['cost_item'];
            $this->pagedata['shipping_cost'] = $res['data']['order']['shipping']['cost_shipping'];
            $this->pagedata['pmt_order'] = $res['data']['order']['pmt_order'];
            $this->pagedata['order_chgpointmoney'] = $res['data']['order']['order_chgpointmoney'];
            $this->pagedata['total_amount'] = $res['data']['order']['total_amount'];
            $this->pagedata['pay'] = $res['data']['order']['payment']['app_display_name'];

            $this->page('wap/myorders/dismsg.html');
        }
    }

//    取消订单
    function canorder($oid){
        $oid = $_POST['oid'];
        $input['method'] = array("file"=>"mobileapi_rpc_express","action"=>"delorder");
        $input['data'] = array('order_id'=>$oid);
        $res = $this->getApi($input);
        echo json_encode($res);
    }

//    查看物流
    function exp($oid){
        $input['method'] = array("file"=>"mobileapi_rpc_express","action"=>"order_exp");
        $input['data'] = array('order_id'=>$oid);
        $res = $this->getApi($input);
        $this->pagedata['exp'] = $res['data'];
        if(count($res['data']) != 2){
            $this->page('wap/myorders/chkexp.html');
        }
        $this->pagedata['first'] = $res['data']['msg'][0];
        array_shift($res['data']['msg']);
        $this->pagedata['res'] = $res['data']['msg'];
        $this->page('wap/myorders/chkexp.html');
    }

}